smlimitlessfandomcom-20200214-history
Tile
A tile is a visible object that is found in levels. Sprites can collide with tiles - that is, if a sprite's translation according to its velocity causes its hitbox to intersect the tile's hitbox, the sprite will be translated so the hitboxes are no longer colliding. Most tiles are square, although some are shaped like right triangles. Tiles are contained within layers, which allows many useful actions on them, such as moving them and hiding or showing them. Tile Base Class All tiles inherit from the SMLimitless.Sprites.Tile abstract class. This class defines the basic functionality of all tiles, including standard abstract methods to initialize, load content, draw, and update the tile. This class also defines a set of basic properties that can be modified in the Level Editor. A property, TileCollisionType CollisionType, defines how the sprite collides with the tile. Finally, the base class defines methods to check and resolve collisions between the tile and a sprite. The base class does not define any graphics, this is saved for deriving classes. Sloped Tiles Sloped tiles are tiles that use a Right Triangle as a collision hitbox. The base class, SMLimitless.Sprites.SlopedTile, is an abstract class that inherits from the Tile abstract class. It defines which two sides of the normally-square hitbox have been replaced with the sloped edge, and has a property returning its hitbox. Same Behavior, Different Graphics A normal Mario game, as well as SMBX, has dozens or hundreds of tiles that behave the same but look visually different. For example, many tiles act like simple solid tiles with no other behavior, but all of them have different graphics. Rather than write hundreds of tile classes that only differ in what resource name they use to load graphics, tiles can be told upon their initialization which resource name to use. Therefore, one only needs to write tile classes for tiles that differ in behavior. Now, the level might decide to load a tile with any kind of Graphics Object, excluding complex objects. Therefore, deriving tile classes should store their graphics as an IGraphicsObject reference instead of expecting one kind of graphics object. The IGraphicsObject interface defines methods for loading, updating, and drawing graphics objects regardless of their kind. Tiles and the Sprite Engine Tiles are part of the Sprite Engine. They are stored in sprite assemblies that reference SMLimitless.exe and use its base type for tiles. Tiles are loaded from assemblies at level load much like sprites are. Implementing Tiles Users can implement their own tiles by creating classes that derive from the Tile base class. All properties and some methods are already implemented and can be overriden, but this isn't required. The methods to load content and update and draw the tile, as well as the methods to handle collisions with sprites, are abstract and derived classes must provide an implementation. These implementations can be left empty if no action is needed for the method. Tiles can store their graphics by holding a reference to an IGraphicsObject, as discussed above. That object can be drawn within the Draw() method.